﻿using AutoMapper;
using MediatR;
using T.S.BaseData.Api.AppClinet.Commend.Cultivationinfo;
using T.S.BaseData.Api.Dto.Cultivationinfo;
using T.S.BaseData.Api.Dto.Goods;
using T.S.BaseData.Domain.Entity;
using T.S.BaseData.ErrorCode;
using T.S.BaseData.Infrastructure.Base;

namespace T.S.BaseData.Api.AppClinet.CommendHand.Cultivationinfo
{
    public class CultivationinfoGetCommandHandle : IRequestHandler<CultivationinfoGetCommand, ApiPaging<GetCultivationinfoDto>>
    {

        private readonly IBaseRepository<CultivationInfo> cutlRepo;
        private readonly IMapper mapper;

        public CultivationinfoGetCommandHandle(IBaseRepository<CultivationInfo> cutlRepo,
            IMapper mapper)
        {
            this.cutlRepo = cutlRepo;
            this.mapper = mapper;
        }

        public Task<ApiPaging<GetCultivationinfoDto>> Handle(CultivationinfoGetCommand request, CancellationToken cancellationToken)
        {

            ApiPaging<GetCultivationinfoDto> result = new ApiPaging<GetCultivationinfoDto>();

            var cult = cutlRepo.GetAll().Where(x => x.GoodsId == request.Id);

            var model = mapper.Map<List<GetCultivationinfoDto>>(cult);

            result.Iteims = model;
            result.Meg = "养殖信息显示成功";
            result.Code = ApiEnums.Success;

            return Task.FromResult(result);
        }
    }
}
